// By buya

void finishStage(Map@ map, bool portal){
	map.showEffect("quest/party/clear");
	map.playSound("Party1/Clear");
	map.showObject("gate");
	if(portal) map.enablePortal("next00");
}

void giveExp(Players@ players, int exp){
	for(int i=0; i<players.getAmount(); i++)
		if(players[i].getHP() > 0)
            		players[i].giveExp(exp);
}

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	Party@ party = player.getParty();
	Event@ event = player.getMap().getEvent();
  	if(@party == null || @event == null){
  		npc.end();
 	}
	if(state == 0){
  		npc.addText("Hi I am Growlie. I won't eat you if you give me some rice cakes. What do you choose to do?\r\n#L0#I brought you the delicious rice cakes you wanted!#l\r\n#L1#I want to go out!#l");
  		npc.sendSimple();
	}
	else if(state == 1){
		int type = npc.getSelected();
		npc.setVariable("type", type);
		if(type == 0){
  			if(player.getItemAmount(4001101) >= 10){
  				player.giveItem(4001101, -10);
  				finishStage(player.getMap(), false);
  				giveExp(player.getMap().getPlayers(), 1500);
  				player.getMap().getPlayers().changeMap(910010100);
  				Map@ map = player.getChannel().getMap(910010000);
				map.setSpawn(false);
				map.clear();
  				npc.end();
			}
			else {
				npc.addText("You don't have 10 rice cakes! Go and get some!");
				npc.sendNext();
				npc.end();
			}
		}
		else if(type == 1){
			npc.addText("OK come back later with my rice cakes!");
			npc.sendNext();
		}
	}
	else if(state == 2){
		player.changeMap(910010300);
		npc.end();
	}
}